package cn.ichiva.tushare.sdk.tushare.entity;

import cn.ichiva.common.SystemHelper;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Getter
@Setter
public class TuTable implements Serializable {
    private String[] fields;
    private String[][] items;

    @Override
    public String toString() {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < fields.length; i++) {
            buffer.append(format(fields[i]));
        }

        buffer.append(SystemHelper.getLineEnd());
        for (String[] item : items) {
            for (int i = 0; i < item.length; i++) {
                buffer.append(format(item[i]));
            }
            buffer.append(SystemHelper.getLineEnd());
        }
        return buffer.toString();
    }

    private char[] format(String field) {
        if(null == field) field = "null";
        char[] res = new char[16];
        int len = field.length();
        for (int i = 0; i < res.length; i++) {
            if(i < len) res[i] = field.charAt(i);
            else res[i] = ' ';
        }
        return res;
    }
}